package com.aaa.system.Controller.Api;

import com.aaa.entity.Dept;
import com.aaa.system.aop.annotation.Log;
import com.aaa.system.service.DeptService;
import com.aaa.system.vo.DeptVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/api/dept")
public class ApiDeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 查询全部部门 用于用户部门数据回填
     * @return
     */
    @GetMapping("/list")
    public Result<List<Dept>> getInfo(){
        return deptService.findAllDept();
    }

    /**
     * 查询全部部门 模糊 分页
     * @param deptVo
     * @return
     */
    @PostMapping("getAllDept")
    public Result<IPage<Dept>> getAllDept(@RequestBody DeptVo deptVo){
        return deptService.findListDept(deptVo);
    }
    /**
     * 添加或者修改部门信息
     */
    @PostMapping("saveOrUpdate")
    @Log(title = "添加或/修改部门信息",business_type = "1")
    public Result<Boolean> saveOrUpdate(@RequestBody Dept dept){
        return deptService.saveOrUpdate(dept);
    }

    /**
     * 删除部门信息业务
     * @return
     */
    @DeleteMapping("delDate/{deptId}")
    @Log(title = "删除部门信息",business_type = "3")
    public Result<Boolean> deleteDept(@PathVariable Long deptId){
        return deptService.deleteDept(deptId);
    }
    /**
     * 批量删除
     */
    @DeleteMapping("bachDel")
    @Log(title = "批量删除部门信息",business_type = "3")
    public Result<Boolean> bachDel(Long[] deptIds){
        return deptService.bachDel(deptIds);
    }
}
